package com.example.broadcast;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.broadcast.receiver.ShockReceiver;

public class StaticBroadcastActivity extends AppCompatActivity implements View.OnClickListener {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_static_broadcast);
        findViewById(R.id.btn_broadcast).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Log.d("tang", "onClick: ");
        String fullName="com.example.broadcast.receiver.ShockReceiver";
        Intent intent=new Intent();
        intent.setAction(ShockReceiver.SHOCK_ACTION);
        //发送静态广播之时，需要通过setComponentName方法指定接收器完整的路径
        ComponentName componentName=new ComponentName(this,fullName);
        //设置意图的组件信息
        intent.setComponent(componentName);
        sendBroadcast(intent);
    }
}
